var EasyWindow = function(title,content,type,style){
	this.title = title;	
	this.name = parseInt(Math.random()*100000);	
	this.style = style;	
	this.content = content;	
	this.type = typeof type == "undefined"?"common" : type;	
	this.height = ""; 
	this.width = "";	

	this.init = function(){	
		
		var strInit = new EasyWindow.StringBuild();
		strInit.push("<div style=\"width:350px;height:400px;position:absolute;border:1px solid #cccccc;");
		strInit.push("font-family: ��,sans-serif;font-size:12px;top:0px;left:0px;");
		strInit.push("border-bottom:2px solid #E0E0E0;border-right:2px solid #E0E0E0;\" id=\""+ this.name +"\">");
		strInit.push("<table style=\"width:100%;height:25px;cursor:move;background:url(/images/green.gif);\" ");
		strInit.push("cellpadding=\"0\" cellspacing=\"0\">");
		strInit.push("<tr>");
		strInit.push("<td style=\"font-weight:bold;border-bottom:1px solid #cccccc;padding-left:3px;\">"+ this.title +"</td>");
		strInit.push("<td style=\"width:38px;border-bottom:1px solid #cccccc;\">");
		strInit.push("<a href=\"#\"><img src=\"/images/hide.gif\" style=\"border:0;\" alt=\"min\" /></a>&nbsp;");
		strInit.push("<a href=\"#\"><img src=\"/images/close_2.gif\" style=\"border:0;\" alt=\"close\" /></a>");
		strInit.push("</td></tr></table>");
		strInit.push("<div style=\"height:90%;padding:3px;overflow:auto;background:#ffffff;\"></div></div>");
		
		var divInit = document.createElement("div");
		divInit.innerHTML = strInit.toString();
		document.body.appendChild(divInit);
		
		this.setCss();	
		this.startDrag();	
		this.setContent();	
		this.setTop();
		this.setCommond();
		EasyWindow.ArrayW.push(document.getElementById(this.name));	

	};this.init();
};


EasyWindow.ArrayW = new Array();


EasyWindow.StringBuild = function(){
	this.arr = new Array();
	this.push = function(str){
		this.arr.push(str);
	};
	this.toString = function(){
		return this.arr.join("");
	};
};


EasyWindow.Drag = function(o ,oRoot){
	var _self = this;

	this.obj = (typeof oRoot != "undefined") ?oRoot : o;
	this.relLeft = 0;	
	this.relTop = 0;	
	o.onselectstart = function(){
		return false;
	};
	o.onmousedown = function(e){
		e = _self.fixE(e);
		_self.relLeft = e.clientX - _self.fixU(_self.obj.style.left); 
		_self.relTop = e.clientY - _self.fixU(_self.obj.style.top); 
		document.onmousemove = function(e){
			_self.drag(e);
			_self.obj.style.border = "1px dashed #000000";
			_self.obj.style.filter = "alpha(opacity=30)";
			_self.obj.style.opacity = "0.3";
		};
		document.onmouseup	 = function(){
			_self.end();
			_self.obj.style.border = "1px solid #cccccc";
			_self.obj.style.borderBottom = "2px solid #E0E0E0";
			_self.obj.style.borderRight = "2px solid #E0E0E0";
			_self.obj.style.filter = "alpha(opacity=100)";
			_self.obj.style.opacity = "1";
		};
	};
	this.drag = function(e){	
		e = this.fixE(e);
		var l = e.clientX - this.relLeft;
		var t = e.clientY - this.relTop;
		if (t < 0)
		{
			t = 0;	
		}
		this.obj.style.left = l +"px";
		this.obj.style.top = t +"px";	
	};
	this.end = function(){	
		document.onmousemove = null;
		document.onmouseup = null;
	};
	this.fixE = function(e){	
		if (typeof e == "undefined") e = window.event;
		return e;
	};
	this.fixU = function(u){	
		return parseInt(u.split("p")[0]);
	};
};


EasyWindow.prototype.setCss = function(){

	var obj = document.getElementById(this.name);
	if(typeof this.style != "undefined")
	{
		if(typeof this.style.width != "undefined") obj.style.width = this.style.width;	
		if(typeof this.style.height != "undefined")	obj.style.height = this.style.height;
		if(typeof this.style.top != "undefined") obj.style.top = this.style.top; 
		if(typeof this.style.left != "undefined") obj.style.left = this.style.left; 
		if(typeof this.style.background != "undefined")
		{
			obj.getElementsByTagName("table")[0].style.background = "url("+ this.style.background +")";
		}
	}
	
	this.height = obj.style.height;
	this.width = obj.style.width;
}


EasyWindow.prototype.startDrag = function(){
	var obj = document.getElementById(this.name);
	new EasyWindow.Drag(obj.childNodes[0] ,obj);
};


EasyWindow.prototype.setContent = function(){
	var obj = document.getElementById(this.name).childNodes[1]; 
	if(this.type == "common")
	{
		obj.innerHTML = this.content;
	}
	else 
	{
		var iframe = document.createElement("iframe");
		iframe.width = "100%";
		iframe.height = "100%";
		iframe.frameBorder = 0;
		iframe.src = this.content;
		obj.appendChild(iframe);
	}
};


EasyWindow.prototype.setTop = function(){
	document.getElementById(this.name).onclick = 
	document.getElementById(this.name).onmousedown = 
	function(){
		for(var i=0;i<EasyWindow.ArrayW.length;i++)
		{
			EasyWindow.ArrayW[i].style.zIndex = 1;
		}
		this.style.zIndex = 100;
	};	
};


EasyWindow.prototype.setCommond = function(){
	var _self = this;
	
	var obj = document.getElementById(this.name);
	
	obj.childNodes[0].getElementsByTagName("a")[0].onclick = function(){
		if (obj.childNodes[1].style.display == "")
		{
			obj.style.height = "25px";
			obj.style.width = "350px";
			obj.childNodes[1].style.display = "none";
			this.getElementsByTagName("img")[0].src = "/images/show.gif";
		}
		else
		{
			obj.style.height = _self.height;
			obj.style.width = _self.width;
			obj.childNodes[1].style.display = "";
			this.getElementsByTagName("img")[0].src = "/images/hide.gif";
		}
	};
	
	obj.childNodes[0].getElementsByTagName("a")[1].onclick = function(){  
        obj.innerHTML = "";
		obj.style.display = "none";
		obj.removeNode(true);
		
	};
};


EasyWindow.prototype.getValue = function(){
	return this.content;
};


EasyWindow.prototype.setValue = function(Value){
	this.content = Vlaue;
	this.setContent();
};